package com.abel.domain;

import java.io.Serializable;
import java.util.List;

import com.abel.domain.types.RoleType;

public class UserSession implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -4062771272448611468L;

	private String id;
	
    private AuthPrincipal authPrincipal;

    private Person person;
    
    /**
     * @return the authPrincipal
     */
    public AuthPrincipal getAuthPrincipal()
    {
        return authPrincipal;
    }

    /**
     * @param authPrincipal the authPrincipal to set
     */
    public void setAuthPrincipal(AuthPrincipal authPrincipal)
    {
        this.authPrincipal = authPrincipal;
    }

	/**
	 * @param id the id to set
	 */
	public void setId(String id) {
		this.id = id;
	}

	/**
	 * @return the id
	 */
	public String getId() {
		return id;
	}

	/**
	 * @return the person
	 */
	public Person getPerson() {
		return person;
	}

	/**
	 * @param person the person to set
	 */
	public void setPerson(Person person) {
		this.person = person;
	}
    
	
	public boolean isUserAdmin() {
		
		List<UserRole> userRoles = this.getAuthPrincipal().getRoles();
		
		for (UserRole userRole : userRoles) {
			
			if (userRole.getRole().equals("SUSER")
					|| userRole.getRole().equals("AUSER")) {
				
				return true;
			}
		}
		return false;
	}
    
}
